<?
global $topdir,$db,$topurl;
#$node = $db->query1("select * from node where id = ".$db->sqlint($params["id"]));

$title = "latest pygame project releases";
$desc = "";

include_once "$topdir/ext/feedcreator/feedcreator.class.php";


inc_inclib("image.php");

if (!$_REQUEST["format"]) { $_REQUEST["format"] = "RSS0.91"; }
$format = $_REQUEST["format"];
$fname = "$topdir/cache/releases-$format";

$rss = new UniversalFeedCreator();
#$rss->useCached($format,$fname);

$rss->title = $title;
$rss->description = $desc;
$rss->descriptionHtmlSyndicated = true;
$rss->link = $topurl;
$rss->syndicationURL = $_SERVER["REQUEST_URI"];

$image = new FeedImage();
$image->title = $title;
$image->url = "$topurl/skins/main/poweredby.gif";
$image->link = "$topurl";
$image->description = $desc;
$image->descriptionHtmlSyndicated = true;
$rss->image = $image;

// get your news items from somewhere, e.g. your database:

$release = "`release`";

$r = $db->query("select project.id as pid,project.node_id,project.title,project.image,$release.datetimeon,$release.title as version,$release.id as rid,project.description as p_description,$release.description as r_description , users.title as u_title , users.name as u_name from project,$release,users where $release.project_id = project.id and users.id = project.users_id order by $release.datetimeon desc limit 20"); 
inc_inclib("image.php");

foreach ($r as $e) {
    $item = new FeedItem();
    $item->title = "{$e["title"]} - {$e["version"]}";
//     $item->link = "$topurl/projects/{$e["node_id"]}/{$e["pid"]}/?release_id={$e["rid"]}";
    $item->link = "$topurl/project/{$e["pid"]}/?release_id={$e["rid"]}";
    
    $ifname = "$topdir/shots/{$e["image"]}";
    $img = "";
    if ($e["image"] != "" && file_exists($ifname)) {
        $img = image_thumb($ifname,124,93,"jpg",50);
        }

    
    $desc = $e["r_description"];
    if (!isset($desc)) $desc = $e["p_description"];
    if (strlen($img) && file_exists("$topdir/thumb/$img")) {
        $desc = "<img src='$topurl/thumb/$img' align=right>\n$desc";
        }
    
    $item->description = $desc;
    
    
    $item->descriptionHtmlSyndicated = true;
    $item->date = strtotime($e["datetimeon"]);
    $item->source = $topurl;
    $item->author = "{$e["u_title"]} ({$e["u_name"]})";
    if (strlen($img) && file_exists("$topdir/thumb/$img")) {
        $image = new FeedImage();
        $image->url = "$topurl/thumb/$img";
        $item->image = $image;
        }
    $rss->addItem($item);
}

$rss->saveFeed($format, $fname);

?>